home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 1.iso / icons / animator.zip / TIMER.C < prev   
C/C++ Source or Header  |  1993-02-01  |  3KB  |  120 lines

  1. #include "animator.h"
  2.  
  3. static char szClass1[32];
  4. static char szClass2[32];
  5.  
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9.  
  10. HICON NEAR PASCAL       GetNextIcon (short);
  11. VOID NEAR PASCAL        DrawIconic (HWND, HICON);
  12.  
  13. #ifdef __cplusplus
  14. }
  15. #endif
  16.  
  17. //////////////////////////////////////////////////////////////////////////
  18. // TimerCallback - this is the function called by the timer which fires
  19. // off every five milleseconds (or close to that).  It is not exact since
  20. // Windows is message driven.  It steps through the animStruct and
  21. // figures out whether or not it is worthy of animation, and if it is,
  22. // and the user has chosen "Go!", then it decrements a time counter.
  23. // When this time counter has reached 0 or less, we re-initialize the
  24. // counter and change the icon.  This way, all of the animations currently
  25. // animating can use one timer.
  26. //////////////////////////////////////////////////////////////////////////
  27.  
  28. VOID _export CALLBACK TimerCallback (HWND hWnd, UINT uMsg, 
  29.     UINT uIDEvent, DWORD dwTime)
  30. {
  31.     short i;
  32.     
  33.     // For all eight possible animation sessions...
  34.     for (i=0; _lPageFlags && i<MAXANIMATIONS ; i++)
  35.     {
  36.         if (!IsWindow(HWNDANIM(i)) || !ISANIMATING(i) || !HWNDTARGET(i)) 
  37.         {
  38.             continue;
  39.         }
  40.         // If the countdown is at 0...display the next icon:
  41.         if (!COUNTDOWN(i))
  42.         {
  43.             HICON hIcon = GetNextIcon(i);
  44.  
  45.             SetClassWord (HWNDTARGET(i), GCW_HICON, hIcon);
  46.             InvalidateAll (HWNDTARGET(i),hIcon);
  47.             SET_COUNTDOWN (i, TIMEINT(i)-(TIMEINT(i)%MINTIME));
  48.         }
  49.         // Otherwise, decrement the countdown by MINTIME amount.
  50.         else
  51.         {
  52.             SET_COUNTDOWN (i, COUNTDOWN(i)-MINTIME);
  53.         }
  54.     }
  55. }
  56.  
  57.  
  58.  
  59. //////////////////////////////////////////////////////////////////////////
  60. // GetNextIcon() - shifts through the list of icons.
  61. //////////////////////////////////////////////////////////////////////////
  62.  
  63. HICON NEAR PASCAL GetNextIcon(short i)
  64. {
  65.  
  66.     if (HICONS(i)[INDEX(i)+1] == (HICON)NULL)
  67.     {
  68.         SET_INDEX (i, 0);
  69.     }
  70.     else
  71.     {
  72.         SET_INDEX (i, INDEX(i)+1);
  73.     }
  74.     return HICONS(i)[INDEX(i)] ;
  75. }
  76.  
  77.  
  78.  
  79. //////////////////////////////////////////////////////////////////////////
  80. // InvalidateAll() - Enumerates the sibling instances of a module that
  81. // is loaded, making all of the instances invalidate themselves.
  82. //////////////////////////////////////////////////////////////////////////
  83.  
  84. VOID WINAPI InvalidateAll (HWND hWnd, HICON hIcon)
  85. {
  86.     HWND hWndNext;
  87.               
  88.     if (!IsWindow(hWnd)) return;
  89.  
  90.     GetClassName (hWnd, (LPSTR)szClass1, sizeof(szClass1));
  91.  
  92.     for (hWndNext = GetWindow((HWND)hWnd,GW_HWNDFIRST); // was GetWindow(hWnd...
  93.          hWndNext;     
  94.          hWndNext = GetWindow(hWndNext, GW_HWNDNEXT))
  95.     {
  96.         GetClassName (hWndNext,(LPSTR)szClass2,sizeof(szClass2));
  97.  
  98.         if (lstrcmp ((LPSTR)szClass1, (LPSTR)szClass2) == 0)
  99.         {
  100.             DrawIconic(hWndNext, hIcon);
  101.         }
  102.     }
  103. }
  104.  
  105.  
  106. //////////////////////////////////////////////////////////////////////////
  107. // DrawIconic() - If iconic, it goes a head and tells the minimized 
  108. // window to redraw its non-client.
  109. //////////////////////////////////////////////////////////////////////////
  110.  
  111. VOID NEAR PASCAL DrawIconic (HWND hWnd, HICON hIcon)
  112. {
  113.     
  114.     if (IsIconic(hWnd))
  115.     {
  116.         RedrawWindow (hWnd, (LPRECT)NULL, (HRGN)NULL,
  117.             RDW_ERASE|RDW_FRAME|RDW_INTERNALPAINT|RDW_INVALIDATE);
  118.     }
  119. }
  120.